import {app} from 'electron'
const packageJson = require('../../package.json');
import {decryptByDESModeCBC, encryptByDESModeCBCUtf8to64} from "@/common/utils/des";
import * as path from "path";
const fs= require("fs");

const configPath = path.join(process.cwd(),'./resources/config.json');

export function configRead() {
  return new Promise((resolve, reject) => {
    fs.readFile(configPath, "utf8", (err, data) => {
      if(err || !data){
        reject(err)
        return
      }
      const obj = JSON.parse(data);
      if(obj && obj.data){
        const info = JSON.parse(decryptByDESModeCBC(obj.data))
        resolve(info.shopId)
      }else{
        reject()
      }
    });
  })
}
export function configWrite(shopId) {
  return new Promise((resolve, reject) => {
    fs.writeFile(configPath, JSON.stringify({
      data: encryptByDESModeCBCUtf8to64(JSON.stringify({shopId}))
    }), () => {
      resolve(shopId)
    })
  })
}
